package com.zy.algorithm.v3.array

import com.zy.view.DIYSortView
import com.zy.utils.data.Point
import com.zy.utils.data.auto.AutoIndexElement
import com.zy.utils.data.auto.AutoNodeStep
import com.zy.utils.data.auto.Coordinate
import java.util.ArrayList

//https://leetcode.cn/problems/remove-element/?envType=study-plan-v2&envId=top-interview-150
open class LeetCode0027 : BaseV3ArrayFragment() {
    private var array1 = intArrayOf(1, 2, 2, 3, 0, 4, 2, 5, 2, 3)
    private var array2 = intArrayOf(2)

    private val ass1 = builder.setOriginX(3).setOriginY(3).setV("^").setIndex(999).build(
        Point.Type.SUB_SCRIPT
    )
    private val ass2 = builder.setOriginX(3).setOriginY(1).setV("V").setIndex(888).build(
        Point.Type.SUB_SCRIPT
    )

    private val ass3 = builder.setOriginX(3).setOriginY(6).setV("newSize").setIndex(777).build(
        Point.Type.SUB_SCRIPT
    )

    private val newSize = builder.setOriginX(5).setOriginY(6).setV("0").setIndex(666).build(
        Point.Type.SUB_SCRIPT
    )

    override fun getInitD(): Int {
        return 150
    }

    override fun setData(diyV4: DIYSortView) {
        //diyV4.changeType = 1
        diyV4.setD(getInitD())

        diyV4.create(3, 2, array1, Point.Type.DEFAULT)
        diyV4.create(3, 4, array2, Point.Type.DEFAULT)

        //diyV4.addNoMoveAssistList(1, 5, array2, Point.Type.DEFAULT)

        //diyV4.addAss(1, 1, "V")
        addAss()
        addAction("下标+1") {
            newSize.v?.let {
                val offset = it.toInt().plus(1)
                newSize.v = offset.toString()
                indexAddAdd(offset)
                //diyV4.invalidate()
            }
        }
    }

    private fun indexAddAdd(offset: Int) {
        val list: MutableList<AutoNodeStep> = ArrayList<AutoNodeStep>()


        val assElement = AutoIndexElement(888, Coordinate(3 + offset, 1))
        list.add(AutoNodeStep(listOf(assElement)))

        diyV4.autoMove(list)
    }

    override fun autoMove(diyV4: DIYSortView) {
        super.autoMove(diyV4)
    }


    private fun addAss() {
        diyV4.addPoint(ass1)
        diyV4.addPoint(ass2)
        diyV4.addPoint(ass3)
        diyV4.addPoint(newSize)
    }
}